#!/usr/bin/python

### VOLUME-APPLET ########################################
# This is a collection of backends for volume-applet     #
# written by Mitchell Nemitz [mitchell.nemitz@gmail.com] #
##########################################################

class ALSA:
    def __init__(self):
        try:
            import alsaaudio
            self.alsa = alsaaudio.Mixer('Master')
        except:
            print "Error: Failed to import alsaaudio"
            exit()
    
    def get_volume(self):
        return self.alsa.getvolume()[0]
    
    def set_volume(self, volume):
        self.alsa.setvolume(int(volume))
    
    def get_mute(self):
        if self.alsa.getmute()[0] == 0: return False
        else: return True
    
    def set_mute(self, mute):
        if mute: self.alsa.setmute(1)
        else:    self.alsa.setmute(0)
